﻿/************************************************************************
* Copyright (c) 2018 All Rights Reserved.
* 命名空间：ZTService
* 文件名：ZtBll
* 创建人：David Rodríguez
* 创建时间：2018/7/31 星期二 9:42:12
* 描述：智投业务逻辑
*************************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using DavidHelper;
using ZTService.Bet;
using ZTService.Modle;

namespace ZTService
{
    public class ZtBll
    {
        public static Dictionary<int, BetA> BetTimerDic = new Dictionary<int, BetA>();

        public static BaseRe StartEngine(Root model)
        {
            //校验用户
            var bs = Common.SystemList.FirstOrDefault(x => x.BetEncode == model.encode);
            if (bs == null)
            {
                NlogHelper.LogWriter("未找到该用户符合的子系统,请检查encode字段", NlogHelper.LogStatus.Error);
                return new BaseRe()
                {
                    IsSuccess = false,
                    Msg = "未找到该用户符合的子系统,请检查encode字段！",
                    Ext = 0
                };
            }

            if (BetTimerDic.ContainsKey(model.uid))
                return new BaseRe()
                {
                    IsSuccess = false,
                    Msg = "该用户正在智投中...",
                    Ext = 0
                };

            var a = new BetA();
            foreach (var m in model.configs)
            {
                if (m.kindid.Equals(Convert.ToInt32(KindId.北京赛车)))
                {
                    a.Pk10A.BetList.Add(m);
                    a.Pk10A.Uid = model.uid;
                    a.Pk10A.Encode = model.encode;
                }
                else if (m.kindid.Equals(Convert.ToInt32(KindId.重庆时时彩)))
                {
                    a.CqsscA.BetList.Add(m);
                    a.CqsscA.Uid = model.uid;
                    a.CqsscA.Encode = model.encode;
                }
            }

            return new BaseRe()
            {
                IsSuccess = true,
                Msg = "系统投注中...",
                Ext = 0
            };
        }


        public static BaseRe EndEngine(int uid)
        {
            if (BetTimerDic.ContainsKey(uid))
            {
                BetTimerDic.Remove(uid);
            }

            return new BaseRe()
            {
                IsSuccess = true,
                Msg = "退出成功！",
                Ext = 0
            };
        }
    }
}